# tthsum makefile
# 
# Makefile for GNU Make.

.PHONY: all clean dists install manual tthsum uninstall

ifeq ($(ARCH),)
  ARCH = $(shell uname -m)
endif
ifndef $(BIN)
  BIN = $(DESTDIR)/usr/local/bin
endif
ifndef $(MAN)
  MAN = $(DESTDIR)/usr/local/man
endif


CC = gcc
CFLAGS = -fomit-frame-pointer -Wall -O3 -march=$(ARCH)
LDFLAGS = -Wall -O3 -march=$(ARCH)
GZIP = gzip -9 -c
RM = rm -rf

CPPFLAGS = -DUSE_SETERROR2 -DNDEBUG

BINS = obj-$(ARCH)
SHARES = share
SRC = \
	base32.c \
	escape.c \
	getopt.c \
	main.c \
	read.c \
	texts.c \
	thex.c \
	tiger.c \
	tthsum.c \
	utf8.c
OBJS = $(patsubst %.c,$(BINS)/%.o, $(SRC))


all: tthsum manual

install: tthsum manual
	install -d $(BIN) $(MAN)/man1
	install $(BINS)/tthsum $(BIN)
	install -m644 $(SHARES)/tthsum.1.gz $(MAN)/man1

uninstall:
	$(RM) $(BIN)/tthsum
	$(RM) $(MAN)/man1/tthsum.1.gz

tthsum: $(BINS)/tthsum

manual: $(SHARES)/tthsum.1.gz

$(SHARES)/tthsum.1.gz: tthsum.1
	@mkdir -p $(SHARES)
	$(GZIP) $< > $@

dists: clean
	sh -c 'X=`basename \`pwd\`` ; \
		tar zvcf ../$$X.tar.gz -C.. $$X'
	sh -c 'X=`basename \`pwd\`` ; \
		tar jvcf ../$$X.tar.bz2 -C.. $$X'
	#sh -c 'X=`basename \`pwd\`` ; cp ../$$X.tar.gz /usr/src/rpm/SOURCES/'
	#rpm -bs rpm/tthsum.spec
	#rpm -bb rpm/tthsum.spec

clean:
	$(RM) $(BINS) $(SHARES)

$(BINS)/%.o: %.c
	@mkdir -p $(BINS)
	$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@

$(BINS)/tthsum: $(OBJS)
